package at.florian.dulzky.crawler;

import java.util.ArrayList;

public class Stack {
	
	private ArrayList<String> stack;
	private ArrayList<String> used;
	
	public Stack(){
		this.stack = new ArrayList<String>();
		this.used = new ArrayList<String>();
	}
	
	public void addAddress(String address)
	{
		boolean douple = false;
		if(!this.used.isEmpty()){
			for(String usedAddress : this.used){
				if(usedAddress.equals(address)){
					douple = true;
				}
			}
		}
		if(!douple){
			this.stack.add(address);
		}
	}
	
	public void setMainSite(String address)
	{
		this.addAddress(address);
	}
	
	public String getNextAddress(){
		int index = this.stack.size();
		index--;
		String returnStr = this.stack.get(index);
		this.used.add(returnStr);
		this.stack.remove(index);
		return returnStr;
	}
	
	public boolean hasNext(){
		if(!this.stack.isEmpty()){
			return true;
		}
		return false;
	}
}
